<?php

class XUser {
	public $cookie, $authenticator;
	
	private $_currentUser=false;
	
	public function __construct () {
		session_start();
		
		$this->cookie &= XT::$registry->http-cookie;
		$this->authenticator = $this->getAuthenticator();
	}
	
	public function getID () {
		return $_SESSION['UID'];
	}
	
	public function setID ($id) {
		$_SESSION['UID'] = $id;
	}
	
	public function current () {
		return $this->_currentUser;
	}
	
	public function authenticate () {
		if(!isset($_SESSION['UID']) && $this->cookie->___xtua) {
			$data = $this->authenticator->decodeCookie($this->cookie->___xtua);
			
			if(($user = $this->getUserByID($data['name']))===true) {
				if($this->authenticator->hashHashPassword($user['password']) == $data['passwordHash']) {
					$this->setID($user['name']);
					$this->_currentUser = $user;
				}
			}
		}
	}
	
	public function getAuthenticator () {
		include      DIR.'components'.DS.'user'.DS.'IAuthenticator.php';
		require_once DIR.'components'.DS.'user'.DS.'authenticator'.DS.'system.php';
		
		return new Authenticator;
	}
	
	public function getUserByID ($id) {
		
	}
}